import type { IFormItem } from '@/components/NFormBuilder/types'
import type { CreateFormItemsOptions } from '@/types/fcform'
import { ScConstants } from '@/components/NFormBuilder/unit/ScConstants'
import IconSelector from '@/components/nComponents/IconSelector'
import type { TreeSelectOption } from 'naive-ui'
export const createFormItems = (options: CreateFormItemsOptions): IFormItem[] => {
  const { formData } = options
  const treeOptions = computed<TreeSelectOption[]>(() => {
    return [
      {
        id: '-1',
        name: '根目录',
        children: options.tableData.value as unknown as TreeSelectOption[],
      },
    ]
  })
  const sc = new ScConstants(24)
  return [
    sc.radio('类型', 'menuType', {
      options: [
        {
          label: '菜单',
          value: '0',
        },
        {
          label: '按钮',
          value: '1',
        },
      ],
    }),
    sc.tree('上级id', 'parentId', {
      options: treeOptions,
      labelField: 'name',
      valueField: 'id',
      childrenField: 'children',
    }),
    {
      ...sc.input('菜单名称', 'name'),
      hidden: () => formData.value.menuType !== '0',
    },
    {
      ...sc.input('name', 'enName'),
      hidden: () => formData.value.menuType !== '0',
    },
    {
      ...sc.input('Path', 'path'),
      hidden: () => formData.value.menuType !== '0',
    },
    {
      ...sc.input('文件路径', 'component', {
        placeholder: 'views/operation/home/index',
      }),
      hidden: () => formData.value.menuType !== '0',
    },
    {
      ...sc.switch('详情', 'keepAlive'),
      hidden: () => formData.value.menuType !== '0',
    },
    {
      ...sc.switch('是否展示下级', 'showNext'),
      hidden: () => formData.value.menuType !== '0',
    },
    {
      ...sc.other('图标', 'icon', IconSelector),
      hidden: () => formData.value.menuType !== '0',
    },
    {
      ...sc.input('权限名称', 'name'),
      hidden: () => formData.value.menuType !== '1',
    },
    {
      ...sc.input('权限标识', 'permission'),
      hidden: () => formData.value.menuType !== '1',
    },
    sc.number('权重', 'sortOrder'),
  ]
}
